﻿
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

/// <summary>
/// 全局异常控制器
/// </summary>
public class GlobalException : IExceptionFilter
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="context"></param>
    public void OnException(ExceptionContext context)
    {
        if (context.Exception.GetType() == typeof(Furion.FriendlyException.AppFriendlyException))
        {
            context.Result = new JsonResult(new { state = false, code = 200, msg = context.Exception.Message });
        }
        else
        {
            context.Result = new JsonResult(new { state = false, code = 500, msg = "系统异常", errmsg = context.Exception.Message });
        }
    }
}

